package com.ruoyi.xds.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.xds.domain.XdsClass;
import com.ruoyi.xds.service.IXdsClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 栏目分类Controller
 *
 * @author ruoyi
 * @date 2025-08-27
 */
@RestController
@RequestMapping("/system/class")
public class XdsClassController extends BaseController {
    @Autowired
    private IXdsClassService huopuClassService;

    /**
     * 查询栏目分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:class:list')")
    @GetMapping("/list")
    public TableDataInfo list(XdsClass huopuClass) {
        startPage();
        List<XdsClass> list = huopuClassService.selectHuopuClassList(huopuClass);
        return getDataTable(list);
    }

    /**
     * 导出栏目分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:class:export')")
    @Log(title = "栏目分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XdsClass huopuClass) {
        List<XdsClass> list = huopuClassService.selectHuopuClassList(huopuClass);
        ExcelUtil<XdsClass> util = new ExcelUtil<XdsClass>(XdsClass.class);
        util.exportExcel(response, list, "栏目分类数据");
    }

    /**
     * 获取栏目分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:class:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(huopuClassService.selectHuopuClassById(id));
    }

    /**
     * 新增栏目分类
     */
    @PreAuthorize("@ss.hasPermi('system:class:add')")
    @Log(title = "栏目分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XdsClass huopuClass) {
        return toAjax(huopuClassService.insertHuopuClass(huopuClass));
    }

    /**
     * 修改栏目分类
     */
    @PreAuthorize("@ss.hasPermi('system:class:edit')")
    @Log(title = "栏目分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XdsClass huopuClass) {
        return toAjax(huopuClassService.updateHuopuClass(huopuClass));
    }

    /**
     * 删除栏目分类
     */
    @PreAuthorize("@ss.hasPermi('system:class:remove')")
    @Log(title = "栏目分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(huopuClassService.deleteHuopuClassByIds(ids));
    }
}
